from openai import OpenAI

client = OpenAI(
    # defaults to os.environ.get("OPENAI_API_KEY")
    api_key="sk-dqRjVh22RuqhoWNNfwtbPaOrRR5vbsmToMP0NYEUKC0id7xw",
    base_url="https://api.chatanywhere.tech/v1"
    # base_url="https://api.chatanywhere.org/v1"
)

def gpt_35_api(messages: list):
    """为提供的对话消息创建新的回答

    Args:
        messages (list): 完整的对话消息
    """
    completion = client.chat.completions.create(model="gpt-3.5-turbo", messages=messages)
    print(completion.choices[0].message.content)

if __name__ == '__main__':
    messages = [{'role': 'user','content': '鲁迅和周树人的关系'},]

    gpt_35_api(messages)
    